package com.tedu.egweibo.common.exception;

import com.tedu.egweibo.common.result.JsonResult;
import com.tedu.egweibo.common.result.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult doHandleRuntimException(RuntimeException e){
        System.out.println("处理RuntimException");
        log.error(e.getMessage(), e);
        return new JsonResult(StatusCode.OPERATION_FAILED);
    }
    @ExceptionHandler
    public JsonResult doHandlerMethodArgumentNotValidException(MethodArgumentNotValidException e){
        System.out.println("MethodArgumentNotValidException");
        log.error(e.getMessage(), e);
        return new JsonResult(StatusCode.OPERATION_FAILED);
    }



}
